package main

import (
	"misakago"
)

//面板服务
type MsgboardService struct {
	misakago.BaseService

	//阈值
	thold int

	//数据库句柄
	*misakago.DbHandler
}

// NewHandler返回含有请求上下文的Handler.
func NewMsgboardService(t int) *MsgboardService {
	return &MsgboardService{
		thold:     t,
		DbHandler: misakago.NewDbHandler(),
	}
}

//推入一条数据,并尝试清理多余数据
func (service *MsgboardService) PushOne(msg string) {
	var data = make(map[string]interface{})

	data["msg"] = msg
	MsgBoardPush(service.DbHandler, data)

	data["pos"] = service.thold
	MsgBoardPop(service.DbHandler, data)
}

//展示一组数据
func (service *MsgboardService) GetList(count int) []MsgBoardModel {
	var data = make(map[string]interface{})

	data["limit"] = count
	msgs, _ := MsgBoardGet(service.DbHandler, data)
	return msgs
}

//register service
var msgboard_service *MsgboardService = NewMsgboardService(10)
